import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import First from '../components/First'
import CompA from '@/components/CompA'
import CompB from '@/components/CompB'

// 路由配置 path：路径（以斜杠开头），component：对应的路由组件
const routes = [
  {
    path: '/',
    name: 'First',
    component: First,
    children: [
      {
        path: '/compA',
        name: 'CompA',
        component: CompA
      },
      {
        path: '/compB',
        name: 'CompB',
        component: CompB
      }
    ]
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  {
    path: '/about',
    name: 'About',
    // 按需引入，访问这个path时才加载组件
    component: () => import('../views/About.vue')
  }
]

// 创建路由对象
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
